package entity

import (
	"yak.admin/src/util"
)

func InitDb()  {
	db := util.GetMysqlPool().Handler()
	// 报告，药物，医疗器械
	db.CreateTable(&DrugCategory{}, &DrugRisk{}, &DrugReport{}, &DrugAnnex{})
	db.Model(&DrugReport{}).AddForeignKey("category_refer", "drug_category(id)", "RESTRICT", "RESTRICT")
	db.Model(&DrugAnnex{}).AddForeignKey("pid", "drug_report(id)", "RESTRICT", "RESTRICT")
	db.CreateTable(&DeviceRiskDesc{}, &DeviceRiskAnalysis{}, &DeviceReport{}, &DeviceRiskDescAnnex{}, &DeviceRiskAnalysisAnnex{})
	// 报告日志
	db.Table("report_log_0").CreateTable(&ReportLog{})
	db.Table("report_log_1").CreateTable(&ReportLog{})
	db.Table("report_log_2").CreateTable(&ReportLog{})
	db.Table("report_log_3").CreateTable(&ReportLog{})
	db.Table("report_log_4").CreateTable(&ReportLog{})
	db.Table("report_log_5").CreateTable(&ReportLog{})
	db.Table("report_log_6").CreateTable(&ReportLog{})
	db.Table("report_log_7").CreateTable(&ReportLog{})
	db.Table("report_log_8").CreateTable(&ReportLog{})
	db.Table("report_log_9").CreateTable(&ReportLog{})
	// 短信
	db.CreateTable(&Sms{})
	// 用户
	db.CreateTable(&User{})
	db.CreateTable(&ReportDiscuss{}, &DeportDiscussAnnex{}, &ReportDiscussCategory{})
	db.Table("message_0").CreateTable(&Message{})
	db.Table("message_1").CreateTable(&Message{})
	db.Table("message_2").CreateTable(&Message{})
	db.Table("message_3").CreateTable(&Message{})
	db.Table("message_4").CreateTable(&Message{})
	db.Table("message_5").CreateTable(&Message{})
	db.Table("message_6").CreateTable(&Message{})
	db.Table("message_7").CreateTable(&Message{})
	db.Table("message_8").CreateTable(&Message{})
	db.Table("message_9").CreateTable(&Message{})
	db.CreateTable(&Region{})
	// 管理员
	db.CreateTable(&Admin{})
	admin := Admin{
		Username:"root",
		Nickname:"root",
		Group: AdminSuper,
		Type: 1,
	}
	admin.SetPassword("12345678")
	db.Create(&admin)

	db.CreateTable(&ReportBehavior{}, &ReportBehaviorDaily{}, &MessageBehavior{})
	// RBAC
	// db.CreateTable(&AuthItem{}, &AuthRule{}, &AuthItemChild{}, &AuthAssignment{})
	// db.Model(&AuthItem{}).AddForeignKey("rule_name", "`auth_rule`(`name`)", "SET NULL", "CASCADE")
	// db.Model(&AuthItemChild{}).AddForeignKey("parent", "auth_item(name)", "CASCADE", "CASCADE").
	//	AddForeignKey("child", "auth_item(name)", "CASCADE", "CASCADE")
	// db.Model(&AuthAssignment{}).AddForeignKey("item_name", "auth_item(name)", "CASCADE", "CASCADE")

}
